from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-27 14:12:57.490576
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 27, Aug, 2021
Time: 14:13:02
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.8124
Nobs: 396.000 HQIC: -46.3588
Log likelihood: 4282.93 FPE: 5.14019e-21
AIC: -46.7173 Det(Omega_mle): 4.10678e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.434238 0.094978 4.572 0.000
L1.Burgenland 0.104908 0.049045 2.139 0.032
L1.Kärnten -0.116160 0.024430 -4.755 0.000
L1.Niederösterreich 0.158143 0.106305 1.488 0.137
L1.Oberösterreich 0.137448 0.103976 1.322 0.186
L1.Salzburg 0.281274 0.051481 5.464 0.000
L1.Steiermark 0.028046 0.068274 0.411 0.681
L1.Tirol 0.110799 0.053840 2.058 0.040
L1.Vorarlberg -0.117157 0.048728 -2.404 0.016
L1.Wien -0.014769 0.093806 -0.157 0.875
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.021470 0.220552 0.097 0.922
L1.Burgenland -0.043515 0.113890 -0.382 0.702
L1.Kärnten 0.036003 0.056729 0.635 0.526
L1.Niederösterreich -0.253859 0.246854 -1.028 0.304
L1.Oberösterreich 0.532956 0.241446 2.207 0.027
L1.Salzburg 0.311190 0.119546 2.603 0.009
L1.Steiermark 0.115015 0.158542 0.725 0.468
L1.Tirol 0.307736 0.125024 2.461 0.014
L1.Vorarlberg -0.008667 0.113153 -0.077 0.939
L1.Wien -0.006743 0.217831 -0.031 0.975
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.253596 0.048451 5.234 0.000
L1.Burgenland 0.087204 0.025020 3.485 0.000
L1.Kärnten -0.001581 0.012462 -0.127 0.899
L1.Niederösterreich 0.219855 0.054229 4.054 0.000
L1.Oberösterreich 0.167712 0.053041 3.162 0.002
L1.Salzburg 0.036506 0.026262 1.390 0.165
L1.Steiermark 0.014856 0.034829 0.427 0.670
L1.Tirol 0.062116 0.027466 2.262 0.024
L1.Vorarlberg 0.059608 0.024858 2.398 0.016
L1.Wien 0.101077 0.047854 2.112 0.035
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181361 0.047151 3.846 0.000
L1.Burgenland 0.045426 0.024348 1.866 0.062
L1.Kärnten -0.007324 0.012128 -0.604 0.546
L1.Niederösterreich 0.133680 0.052774 2.533 0.011
L1.Oberösterreich 0.316633 0.051618 6.134 0.000
L1.Salzburg 0.099124 0.025557 3.878 0.000
L1.Steiermark 0.137275 0.033894 4.050 0.000
L1.Tirol 0.075114 0.026729 2.810 0.005
L1.Vorarlberg 0.054738 0.024191 2.263 0.024
L1.Wien -0.036474 0.046570 -0.783 0.434
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.209624 0.093914 2.232 0.026
L1.Burgenland -0.061240 0.048496 -1.263 0.207
L1.Kärnten -0.035975 0.024156 -1.489 0.136
L1.Niederösterreich 0.114570 0.105114 1.090 0.276
L1.Oberösterreich 0.183675 0.102811 1.787 0.074
L1.Salzburg 0.258907 0.050904 5.086 0.000
L1.Steiermark 0.078330 0.067509 1.160 0.246
L1.Tirol 0.123282 0.053237 2.316 0.021
L1.Vorarlberg 0.111043 0.048182 2.305 0.021
L1.Wien 0.021935 0.092755 0.236 0.813
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.024385 0.073087 0.334 0.739
L1.Burgenland 0.026300 0.037741 0.697 0.486
L1.Kärnten 0.050587 0.018799 2.691 0.007
L1.Niederösterreich 0.206957 0.081803 2.530 0.011
L1.Oberösterreich 0.342351 0.080011 4.279 0.000
L1.Salzburg 0.046734 0.039616 1.180 0.238
L1.Steiermark -0.001800 0.052538 -0.034 0.973
L1.Tirol 0.114539 0.041431 2.765 0.006
L1.Vorarlberg 0.061089 0.037497 1.629 0.103
L1.Wien 0.130079 0.072186 1.802 0.072
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190192 0.089134 2.134 0.033
L1.Burgenland 0.020150 0.046028 0.438 0.662
L1.Kärnten -0.057201 0.022927 -2.495 0.013
L1.Niederösterreich -0.141339 0.099764 -1.417 0.157
L1.Oberösterreich 0.200019 0.097579 2.050 0.040
L1.Salzburg 0.029077 0.048314 0.602 0.547
L1.Steiermark 0.303604 0.064073 4.738 0.000
L1.Tirol 0.490874 0.050528 9.715 0.000
L1.Vorarlberg 0.068091 0.045730 1.489 0.136
L1.Wien -0.100632 0.088035 -1.143 0.253
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160839 0.097047 1.657 0.097
L1.Burgenland -0.004626 0.050114 -0.092 0.926
L1.Kärnten 0.063450 0.024962 2.542 0.011
L1.Niederösterreich 0.202872 0.108620 1.868 0.062
L1.Oberösterreich -0.119564 0.106240 -1.125 0.260
L1.Salzburg 0.242201 0.052602 4.604 0.000
L1.Steiermark 0.151961 0.069761 2.178 0.029
L1.Tirol 0.050163 0.055013 0.912 0.362
L1.Vorarlberg 0.121029 0.049789 2.431 0.015
L1.Wien 0.134837 0.095849 1.407 0.159
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.485429 0.052649 9.220 0.000
L1.Burgenland -0.011828 0.027187 -0.435 0.664
L1.Kärnten -0.010325 0.013542 -0.762 0.446
L1.Niederösterreich 0.203737 0.058928 3.457 0.001
L1.Oberösterreich 0.263703 0.057637 4.575 0.000
L1.Salzburg 0.020749 0.028538 0.727 0.467
L1.Steiermark -0.025864 0.037846 -0.683 0.494
L1.Tirol 0.070595 0.029845 2.365 0.018
L1.Vorarlberg 0.058161 0.027011 2.153 0.031
L1.Wien -0.051551 0.052000 -0.991 0.322
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.017846 0.078579 0.134814 0.128119 0.041907 0.068095 0.003428 0.173302
Kärnten 0.017846 1.000000 -0.054033 0.129133 0.046441 0.069683 0.456505 -0.093717 0.095394
Niederösterreich 0.078579 -0.054033 1.000000 0.282316 0.082182 0.272233 0.018439 0.148053 0.247953
Oberösterreich 0.134814 0.129133 0.282316 1.000000 0.176296 0.288464 0.159588 0.116293 0.138166
Salzburg 0.128119 0.046441 0.082182 0.176296 1.000000 0.126082 0.054484 0.108939 0.049599
Steiermark 0.041907 0.069683 0.272233 0.288464 0.126082 1.000000 0.127536 0.087658 -0.025577
Tirol 0.068095 0.456505 0.018439 0.159588 0.054484 0.127536 1.000000 0.041841 0.117579
Vorarlberg 0.003428 -0.093717 0.148053 0.116293 0.108939 0.087658 0.041841 1.000000 -0.047479
Wien 0.173302 0.095394 0.247953 0.138166 0.049599 -0.025577 0.117579 -0.047479 1.000000